﻿using _5E.Infrastructure.Logging;
using _5E.Infrastructure.UnitOfWork;
using _5E.NHibernateRepository.UnitOfWork;
using StoneAge.Contract;
using StoneAge.Controller.Handlers;
using StoneAge.Controller.Request;
using StoneAge.Infrastructure.Configuration;
using StoneAge.Infrastructure.Logging;
using StoneAge.Models.Repository;
using StoneAge.Repository;
using StoneAge.Service;
using StructureMap;

namespace StoneAge.Controller.Registry
{
    public class StructureMapRegistry
    {
        public static void Initialize()
        {
            ObjectFactory.Initialize(x => x.AddRegistry<InitializeRegistry>());

            ApplicationSettingsFactory.InitializeApplicationSettingsFactory(ObjectFactory.GetInstance<IApplicationSettings>());
            LoggingFactory.InitializeLogFactory(ObjectFactory.GetInstance<ILogger>());
        }

        class InitializeRegistry : StructureMap.Configuration.DSL.Registry
        {
            public InitializeRegistry()
            {
                //repository
                For<IAccountRepository>().Use<AccountRepository>();
                For<ICoordinateRepository>().Use<CoordinateRepository>();
                For<ILevelRepository>().Use<LevelRepository>();
                For<IMapRepository>().Use<MapRepository>();
                For<IMapAreaRepository>().Use<MapAreaRepository>();
                For<IRoleRepository>().Use<RoleRepository>();

                //service
                For<IAccountService>().Use<AccountService>();
                For<IMapService>().Use<MapService>();
                For<IRoleService>().Use<RoleService>();

                //其他
                For<IApplicationSettings>().Use<WebConfigApplicationSettings>();
                For<IHandlerFactory>().Use<HandlerFactory>();
                For<ILogger>().Use<Log4NetAdapter>();
                For<IUnitOfWork>().Use<NHibernateUnitOfWork>();
                For<IWebRequestFactory>().Use<WebRequestFactory>();
            }
        }
    }
}
